# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
        if not l1:
            return l2
        if not l2:
            return l1
        if l1.val>l2.val:
            temp=l2
            l2=l1
            l1=temp
        temp=l1
        while l2:
            while temp.next and l2.val>temp.next.val:
                temp=temp.next
            record1=temp.next
            record2=l2.next
            temp.next=l2
            l2.next=record1
            l2=record2
        return l1

'''
执行用时：
48 ms
, 在所有 Python3 提交中击败了
61.92%
的用户
内存消耗：
13.5 MB
, 在所有 Python3 提交中击败了
12.01%
的用户
'''